﻿using UnityEngine;
using System;

/// <summary>
/// 对象池工具封装
/// </summary>
public class ObjectPool<T> : UniRx.Toolkit.ObjectPool<T> where T : Component
{
    private GameObject m_Prefab;
    private Action<T> m_OnInit;

    public ObjectPool(GameObject prefab, Action<T> onInit = null)
    {
        m_Prefab = prefab;
        m_OnInit = onInit;
    }

    protected override T CreateInstance()
    {
        var target = GameObject.Instantiate(m_Prefab).GetComponent<T>();
        m_OnInit?.Invoke(target);
        return target;
    }
}